<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%
	String path = request.getContextPath();
	request.setAttribute("basePath", path);
%>
<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Faurecia</title>
    <link rel="stylesheet" type="text/css" href="${basePath}/resource/jquery-easyui/themes/default/easyui1.css">
    <link rel="stylesheet" type="text/css" href="${basePath}/resource/jquery-easyui/themes/icon.css">
    <link rel="stylesheet" type="text/css" href="${basePath}/resource/jquery-easyui/themes/color.css">
    <link rel="stylesheet" type="text/css" href="${basePath}/resource/jquery-easyui/demo/demo.css">
    <script type="text/javascript" src="${basePath}/resource/jquery-easyui/jquery.min.js"></script>
    <script type="text/javascript" src="${basePath}/resource/jquery-easyui/jquery.easyui.min.js"></script>
    <style type="text/css">
    	#ff table tr td{
    		height:50px;
    	}
    	.hidenDiv {
    		width:100%
    	}
    	.hidenDiv tr{
    		height:80px;
    		margin-top:40px;
    	}
    	.hidenDiv tr td{
    		width:100%
    	}
    	.txt{
    		font-size:36px;	
    		font-weight:300
    	}
    	.l-btn-text{
    		font-size:26px;	
    	}
    	.itemName{
    		font-size:26px;
    	}
    </style>
</head>
<body>
	<div >
	    <form id="ff" method="post">
	    	<table cellpadding="5">
	    		<tr>
	    			<td  class="txt" align="right" style="width:200px;">服务商:</td>
	    			<td>
	    				<select class="easyui-combobox" data-options="panelHeight:'auto',editable:false" style="width:350px;height:50px;">
	    					<option value="DFYF">DFYF</option>
	    					<option value="DPCA">DPCA</option>
	    					<option value="HD">HD</option>
	    					<option value="DFPV">DFPV</option>
    					</select>
	    			</td>
	    		</tr>
	    		<tr>
	    			<td class="txt" align="right">订单号:</td>
	    			<td><input class="easyui-textbox" type="text" style="width:350px;height:50px"></input></td>
	    			<td style="width:600px" align="right">
	    				<a href="javascript:void(0)" class="easyui-linkbutton" onclick="checkFnc()" style="width:100px;height:40px">出库</a>
	    			</td>
	    		</tr>
    		</table>
    		<table cellpadding="5">
	    		<tr>
	    			<td  class="txt" style="width:200px;">项目</td>
	    			<td  class="txt" style="width:300px;">零件号</td>
	    			<td  class="txt" style="width:500px;">零件名称</td>
	    			<td  class="txt" style="width:300px;">外包装条码</td>
	    		</tr>
	    		<tr>
	    			<td>
	    				<select class="easyui-combobox" id="prog1" name="prog" data-options="panelHeight:'auto',editable:false,onSelect:selectProg1" style="width:200px;height:50px;">
	    					<option value="">--请选择--</option>
	    					<option value="TX9">TX9</option>
	    					<option value="W23R">W23R</option>
	    					<option value="A94">A94</option>
	    					<option value="A94R">A94R</option>
	    					<option value="T93">T93</option>
	    					<option value="T91">T91</option>
    					</select>
	    			</td>
	    			<td>
	    				<input class="easyui-combobox" id="itemCode1" name="itemCode" 
	    					data-options="panelHeight:'300px',editable:false,valueField:'itemCode',textField:'itemCode',url:''" 
	    					style="width:300px;height:50px;"/> 
	    			</td>
	    			<td>
	    				<p class="itemName" id="itemName1"></p>
	    			</td>
	    			<td>
	    				<input class="easyui-textbox" id="outCode1" type="text" style="width:300px;height:50px"></input>
	    			</td>
	    		</tr>
	    		<tr>
	    			<td>
	    				<select class="easyui-combobox" id="prog2" name="prog" data-options="panelHeight:'auto',editable:false,onSelect:selectProg2" style="width:200px;height:50px;">
	    					<option value="">--请选择--</option>
	    					<option value="TX9">TX9</option>
	    					<option value="W23R">W23R</option>
	    					<option value="A94">A94</option>
	    					<option value="A94R">A94R</option>
	    					<option value="T93">T93</option>
	    					<option value="T91">T91</option>
    					</select>
	    			</td>
	    			<td>
	    				<input class="easyui-combobox" id="itemCode2" name="itemCode" 
	    					data-options="panelHeight:'300px',editable:false,valueField:'itemCode',textField:'itemCode',url:''" 
	    					style="width:300px;height:50px;"/> 
	    			</td>
	    			<td>
	    				<p class="itemName" id="itemName2"></p>
	    			</td>
	    			<td>
	    				<input class="easyui-textbox" id="outCode2" type="text" style="width:300px;height:50px"></input>
	    			</td>
	    		</tr>
	    		<tr>
	    			<td>
	    				<select class="easyui-combobox" id="prog3" name="prog" data-options="panelHeight:'auto',editable:false,onSelect:selectProg3" style="width:200px;height:50px;">
	    					<option value="">--请选择--</option>
	    					<option value="TX9">TX9</option>
	    					<option value="W23R">W23R</option>
	    					<option value="A94">A94</option>
	    					<option value="A94R">A94R</option>
	    					<option value="T93">T93</option>
	    					<option value="T91">T91</option>
    					</select>
	    			</td>
	    			<td>
	    				<input class="easyui-combobox" id="itemCode3" name="itemCode" 
	    					data-options="panelHeight:'300px',editable:false,valueField:'itemCode',textField:'itemCode',url:''" 
	    					style="width:300px;height:50px;"/> 
	    			</td>
	    			<td>
	    				<p class="itemName" id="itemName3"></p>
	    			</td>
	    			<td>
	    				<input class="easyui-textbox" id="outCode3" type="text" style="width:300px;height:50px"></input>
	    			</td>
	    		</tr>
	    		<tr>
	    			<td>
	    				<select class="easyui-combobox" id="prog4" name="prog" data-options="panelHeight:'auto',editable:false,onSelect:selectProg4" style="width:200px;height:50px;">
	    					<option value="">--请选择--</option>
	    					<option value="TX9">TX9</option>
	    					<option value="W23R">W23R</option>
	    					<option value="A94">A94</option>
	    					<option value="A94R">A94R</option>
	    					<option value="T93">T93</option>
	    					<option value="T91">T91</option>
    					</select>
	    			</td>
	    			<td>
	    				<input class="easyui-combobox" id="itemCode4" name="itemCode" 
	    					data-options="panelHeight:'300px',editable:false,valueField:'itemCode',textField:'itemCode',url:''" 
	    					style="width:300px;height:50px;"/> 
	    			</td>
	    			<td>
	    				<p class="itemName" id="itemName4"></p>
	    			</td>
	    			<td>
	    				<input class="easyui-textbox" id="outCode4" type="text" style="width:300px;height:50px"></input>
	    			</td>
	    		</tr>
	    		<tr>
	    			<td>
	    				<select class="easyui-combobox" id="prog5" name="prog" data-options="panelHeight:'auto',editable:false,onSelect:selectProg5" style="width:200px;height:50px;">
	    					<option value="">--请选择--</option>
	    					<option value="TX9">TX9</option>
	    					<option value="W23R">W23R</option>
	    					<option value="A94">A94</option>
	    					<option value="A94R">A94R</option>
	    					<option value="T93">T93</option>
	    					<option value="T91">T91</option>
    					</select>
	    			</td>
	    			<td>
	    				<input class="easyui-combobox" id="itemCode5" name="itemCode" 
	    					data-options="panelHeight:'300px',editable:false,valueField:'itemCode',textField:'itemCode',url:''" 
	    					style="width:300px;height:50px;"/> 
	    			</td>
	    			<td>
	    				<p class="itemName" id="itemName5"></p>
	    			</td>
	    			<td>
	    				<input class="easyui-textbox" id="outCode5" type="text" style="width:300px;height:50px"></input>
	    			</td>
	    		</tr>
    		</table>
	    </form>
    </div>
    <script>
    	$(document).ready(function() {
    		$('#outCode1').textbox('textbox').focus();
    		$('#outCode1').textbox('textbox').keydown(function (e) {
                if (e.keyCode == 13) {
                	$('#outCode2').textbox('textbox').focus();
                }
            });
    		$('#outCode2').textbox('textbox').keydown(function (e) {
                if (e.keyCode == 13) {
                	$('#outCode3').textbox('textbox').focus();
                }
            });
    		$('#outCode3').textbox('textbox').keydown(function (e) {
                if (e.keyCode == 13) {
                	$('#outCode4').textbox('textbox').focus();
                }
            });
    		$('#outCode4').textbox('textbox').keydown(function (e) {
                if (e.keyCode == 13) {
                	$('#outCode5').textbox('textbox').focus();
                }
            });
    		$('#outCode5').textbox('textbox').keydown(function (e) {
                if (e.keyCode == 13) {
                	checkFnc();
                }
            });
    	})
    	
    	function checkFnc(){
    		var outCode1 = $("#outCode1").val()?1:0;
    		var outCode2 = $("#outCode2").val()?1:0;
    		var outCode3 = $("#outCode3").val()?1:0;
    		var outCode4 = $("#outCode4").val()?1:0;
    		var outCode5 = $("#outCode5").val()?1:0;
    		var itemCodes = "";
    		if(outCode1 > 0){
    			itemCodes+=$("#itemCode1").combobox('getValue')+";";
    		}
    		if(outCode2 > 0){
    			itemCodes+=$("#itemCode2").combobox('getValue')+";";
    		}
    		if(outCode3 > 0){
    			itemCodes+=$("#itemCode3").combobox('getValue')+";";
    		}
    		if(outCode4 > 0){
    			itemCodes+=$("#itemCode4").combobox('getValue')+";";
    		}
    		if(outCode5 > 0){
    			itemCodes+=$("#itemCode5").combobox('getValue')+";";
    		}
    		
    		var cnt = outCode1+outCode2+outCode3+outCode4+outCode5;
    		if(cnt == 0){
    			$.messager.alert('错误','<p style="color:red">无可发货产品<p>');  
    		}else if(cnt < 5){
    			$.messager.confirm('确认','确定不满车发货？',function(r){    
				    if (r){    
				    	outStockFnc(itemCodes);
				    }    
				});
    		}else{
    			outStockFnc(itemCodes);
    		}
    	}
    	
    	function outStockFnc(itemCodes){
    		$.ajax({
				url:"${basePath}/outstock/outstock/",
				data:{ param: itemCodes },
				async:false,
				dataType : "json",
				success : function(data) {
					if(data.result == 0){
						$.messager.alert('成功','出库成功！');    
					}else if(data.result ==2){
						$.messager.alert('错误','<p style="color:red">库存不足<p>');    
					}else{
						$.messager.alert('错误','<p style="color:red">出库失败<p>');  
					}
					$('#outCode1').textbox('textbox').focus();
				},
				error : function() {
					$.messager.alert('错误','<p style="color:red">出库失败<p>');  
				}
			})
    	}
    	
    	function selectProg1(prog){
    		$("#itemCode1").combobox({
                valueField:'itemCode', //值字段
                textField:'itemCode', //显示的字段
                url:'${basePath}/instock/queryByProg?prog='+prog.value,
                panelHeight:'auto',
                editable:false,//不可编辑，只能选择
                onSelect: function(record){
    				$("#itemName1").html(record.itemName)
    			}
        	});
    	}
    	function selectProg2(prog){
    		$("#itemCode2").combobox({
                valueField:'itemCode', //值字段
                textField:'itemCode', //显示的字段
                url:'${basePath}/instock/queryByProg?prog='+prog.value,
                panelHeight:'auto',
                editable:false,//不可编辑，只能选择
                onSelect: function(record){
    				$("#itemName2").html(record.itemName)
    			}
        	});
    	}
    	function selectProg3(prog){
    		$("#itemCode3").combobox({
                valueField:'itemCode', //值字段
                textField:'itemCode', //显示的字段
                url:'${basePath}/instock/queryByProg?prog='+prog.value,
                panelHeight:'auto',
                editable:false,//不可编辑，只能选择
                onSelect: function(record){
    				$("#itemName3").html(record.itemName)
    			}
        	});
    	}
    	function selectProg4(prog){
    		$("#itemCode4").combobox({
                valueField:'itemCode', //值字段
                textField:'itemCode', //显示的字段
                url:'${basePath}/instock/queryByProg?prog='+prog.value,
                panelHeight:'auto',
                editable:false,//不可编辑，只能选择
                onSelect: function(record){
    				$("#itemName4").html(record.itemName)
    			}
        	});
    	}
    	function selectProg5(prog){
    		$("#itemCode5").combobox({
                valueField:'itemCode', //值字段
                textField:'itemCode', //显示的字段
                url:'${basePath}/instock/queryByProg?prog='+prog.value,
                panelHeight:'auto',
                editable:false,//不可编辑，只能选择
                onSelect: function(record){
    				$("#itemName5").html(record.itemName)
    			}
        	});
    	}
	</script>
</body>
</html>